<template>
  <div class="wrapper">
    正在请求微信中...
  </div>
</template>

<script>
import api from '@/api'
import base64 from '@/util/base64'
export default {
  name: 'Openid',
  data() {
    return {
      redirect: ''
    }
  },
  created () {
    // parse url param
    this.redirect = base64.parse(this.$route.params.redirect)
  },
  mounted () {
    // 这里的是state就是user id, 请注意
    const { code, state } = this.$route.query
    api.Wx.get({
      code,
      user_id: state
    }).then(() => {
      // 后退地址(比如从支付过来)
      // this.$router.push(this.redirect)
      window.location.href = this.redirect
    })
  }
}
</script>
